package com.aspose.cells.a.d.a;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.io.DataOutput;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UTFDataFormatException;

public class zb extends FilterOutputStream implements DataOutput {
   protected boolean a;
   protected int b;
   private int c;
   private int d;

   public zb(OutputStream var1, boolean var2) {
      super(var1);
      this.a = var2;
      this.b = 0;
      this.c = 0;
      this.d = 0;
   }

   public void c() throws IOException {
      this.d();
      if (this.out instanceof zb) {
         ((zb)this.out).c();
      }

   }

   public void close() throws IOException {
      this.c();
      super.close();
   }

   protected void d() throws IOException {
      if (this.d != 0) {
         this.write(this.c);
         this.c = 0;
         this.d = 0;
      }
   }

   public void e() throws IOException {
      this.d();
   }

   public synchronized void write(int b) throws IOException {
      super.write(b);
      ++this.b;
   }

   public void writeBoolean(boolean b) throws IOException {
      if (b) {
         this.write(1);
      } else {
         this.write(0);
      }

   }

   public void writeChar(int c) throws IOException {
      if (this.a) {
         this.write(c & 255);
         this.write(c >>> 8 & 255);
      } else {
         this.write(c >>> 8 & 255);
         this.write(c & 255);
      }

   }

   public void writeByte(int b) throws IOException {
      this.e();
      this.write(b);
   }

   public void a(byte[] var1) throws IOException {
      this.e();

      for(int var2 = 0; var2 < var1.length; ++var2) {
         this.write(var1[var2]);
      }

   }

   public void a(byte[] var1, int var2, int var3) throws IOException {
      this.e();

      for(var3 += var2; var2 < var3; ++var2) {
         this.write(var1[var2]);
      }

   }

   public void a(int[] var1) throws IOException {
      this.e();

      for(int var2 = 0; var2 < var1.length; ++var2) {
         this.write(var1[var2]);
      }

   }

   public void writeShort(int s) throws IOException {
      this.e();
      if (this.a) {
         this.write(s & 255);
         this.write(s >>> 8 & 255);
      } else {
         this.write(s >>> 8 & 255);
         this.write(s & 255);
      }

   }

   public void a(int var1) throws IOException {
      this.e();
      if (this.a) {
         this.write(var1 & 255);
         this.write(var1 >>> 8 & 255);
      } else {
         this.write(var1 >>> 8 & 255);
         this.write(var1 & 255);
      }

   }

   public void writeInt(int i) throws IOException {
      if (this.a) {
         this.write(i & 255);
         this.write(i >>> 8 & 255);
         this.write(i >>> 16 & 255);
         this.write(i >>> 24 & 255);
      } else {
         this.write(i >>> 24 & 255);
         this.write(i >>> 16 & 255);
         this.write(i >>> 8 & 255);
         this.write(i & 255);
      }

   }

   public void a(long var1) throws IOException {
      if (this.a) {
         this.write((int)(var1 & 255L));
         this.write((int)(var1 >>> 8 & 255L));
         this.write((int)(var1 >>> 16 & 255L));
         this.write((int)(var1 >>> 24 & 255L));
      } else {
         this.write((int)(var1 >>> 24 & 255L));
         this.write((int)(var1 >>> 16 & 255L));
         this.write((int)(var1 >>> 8 & 255L));
         this.write((int)(var1 & 255L));
      }

   }

   public void writeLong(long l) throws IOException {
      if (this.a) {
         this.write((int)(l & 255L));
         this.write((int)(l >>> 8 & 255L));
         this.write((int)(l >>> 16 & 255L));
         this.write((int)(l >>> 24 & 255L));
         this.write((int)(l >>> 32 & 255L));
         this.write((int)(l >>> 40 & 255L));
         this.write((int)(l >>> 48 & 255L));
         this.write((int)(l >>> 56 & 255L));
      } else {
         this.write((int)(l >>> 56 & 255L));
         this.write((int)(l >>> 48 & 255L));
         this.write((int)(l >>> 40 & 255L));
         this.write((int)(l >>> 32 & 255L));
         this.write((int)(l >>> 24 & 255L));
         this.write((int)(l >>> 16 & 255L));
         this.write((int)(l >>> 8 & 255L));
         this.write((int)(l & 255L));
      }

   }

   public void writeFloat(float f) throws IOException {
      this.writeInt(Float.floatToIntBits(f));
   }

   public void writeDouble(double d) throws IOException {
      this.writeLong(Double.doubleToLongBits(d));
   }

   public void writeBytes(String s) throws IOException {
      for(int var2 = 0; var2 < s.length(); ++var2) {
         this.writeByte(s.charAt(var2));
      }

   }

   public void writeChars(String s) throws IOException {
      for(int var2 = 0; var2 < s.length(); ++var2) {
         this.writeChar(s.charAt(var2));
      }

   }

   public void writeUTF(String s) throws IOException {
      a(s, this);
   }

   public static void a(String var0, DataOutput var1) throws IOException {
      int var2 = var0.length();
      int var3 = 0;
      char[] var4 = new char[var2];
      byte var6 = 0;
      var0.getChars(0, var2, var4, 0);

      char var5;
      for(int var7 = 0; var7 < var2; ++var7) {
         var5 = var4[var7];
         if (var5 >= 1 && var5 <= 127) {
            ++var3;
         } else if (var5 > 2047) {
            var3 += 3;
         } else {
            var3 += 2;
         }
      }

      if (var3 > 65535) {
         throw new UTFDataFormatException();
      } else {
         byte[] var10 = new byte[var3 + 2];
         int var9 = var6 + 1;
         var10[var6] = (byte)(var3 >>> 8 & 255);
         var10[var9++] = (byte)(var3 >>> 0 & 255);

         for(int var8 = 0; var8 < var2; ++var8) {
            var5 = var4[var8];
            if (var5 >= 1 && var5 <= 127) {
               var10[var9++] = (byte)var5;
            } else if (var5 > 2047) {
               var10[var9++] = (byte)(224 | var5 >> 12 & 15);
               var10[var9++] = (byte)(128 | var5 >> 6 & 63);
               var10[var9++] = (byte)(128 | var5 >> 0 & 63);
            } else {
               var10[var9++] = (byte)(192 | var5 >> 6 & 31);
               var10[var9++] = (byte)(128 | var5 >> 0 & 63);
            }
         }

         var1.write(var10);
      }
   }

   public void b(int var1) throws IOException {
      this.a((long)var1);
   }

   public void c(int var1) throws IOException {
      this.a(var1);
   }

   public void a(float var1) throws IOException {
      this.writeFloat(var1);
   }

   public void a(Color var1) throws IOException {
      this.writeByte(var1.getRed());
      this.writeByte(var1.getGreen());
      this.writeByte(var1.getBlue());
      this.writeByte(0);
   }

   public void b(Color var1) throws IOException {
      this.writeShort(var1.getRed() << 8);
      this.writeShort(var1.getGreen() << 8);
      this.writeShort(var1.getBlue() << 8);
      this.writeShort(var1.getAlpha() << 8);
   }

   public void a(AffineTransform var1) throws IOException {
      this.a((float)var1.getScaleX());
      this.a((float)var1.getShearY());
      this.a((float)var1.getShearX());
      this.a((float)var1.getScaleY());
      this.a((float)var1.getTranslateX());
      this.a((float)var1.getTranslateY());
   }

   public void a(Point[] var1) throws IOException {
      this.a(var1.length, var1);
   }

   public void a(int var1, Point[] var2) throws IOException {
      for(int var3 = 0; var3 < var1; ++var3) {
         this.a(var2[var3]);
      }

   }

   public void a(Point var1) throws IOException {
      this.a((short)var1.x);
      this.a((short)var1.y);
   }

   public void b(Point[] var1) throws IOException {
      this.b(var1.length, var1);
   }

   public void b(int var1, Point[] var2) throws IOException {
      for(int var3 = 0; var3 < var1; ++var3) {
         this.b(var2[var3]);
      }

   }

   public void b(Point var1) throws IOException {
      this.f(var1.x);
      this.f(var1.y);
   }

   public void a(Rectangle var1) throws IOException {
      this.f(var1.x);
      this.f(var1.y);
      this.f(var1.x + var1.width);
      this.f(var1.y + var1.height);
   }

   public void a(Rectangle2D var1) throws IOException {
      this.a((float)var1.getX());
      this.a((float)var1.getY());
      this.a((float)var1.getWidth());
      this.a((float)var1.getHeight());
   }

   public void a(Dimension var1) throws IOException {
      this.f(var1.width);
      this.f(var1.height);
   }

   public void d(int var1) throws IOException {
      this.a((long)var1);
   }

   public void e(int var1) throws IOException {
      this.a((long)var1);
   }

   public void f(int var1) throws IOException {
      this.writeInt(var1);
   }

   public void a(short var1) throws IOException {
      this.writeShort(var1);
   }

   public void b(byte[] var1) throws IOException {
      this.a(var1);
   }

   public void g(int var1) throws IOException {
      this.writeByte(var1);
   }

   public void b(boolean var1) throws IOException {
      this.g(var1 ? 1 : 0);
   }

   public void c(boolean var1) throws IOException {
      this.b(var1 ? 1 : 0);
   }

   public void a(String var1) throws IOException {
      this.a(var1.getBytes("UTF-16LE"));
   }

   public void a(String var1, int var2) throws IOException {
      this.a(var1);

      for(int var3 = var2 - var1.length(); var3 > 0; --var3) {
         this.c(0);
      }

   }

   protected int f() {
      return 4;
   }
}
